﻿@model HY.Model.SysUser
<form class="layui-form layui-form-pane" lay-filter="">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="text" name="UserName" maxlength="50" autocomplete="off" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
            <select name="RoleId" lay-verify="required" lay-search>
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="TrueName" maxlength="50" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">身份证号</label>
        <div class="layui-input-block">
            <input type="text" name="IDNumber" maxlength="18" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" name="PhoneNumber" maxlength="11" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item" style="text-align:center;">
        <button class="layui-btn" id="submit" lay-submit lay-filter="save">保存</button>
        <button class="layui-btn" id="cancel">取消</button>
    </div>
</form>
@section Scripts{
<script type="text/javascript">
    layui.use(function() {
        var form = layui.form;
        var $ = layui.jquery;
        $.ajax({
            url: '/SysRole/Index',
            success: function(res) {
                if (res.Code == 200) {
                    $(res.Data).each(function(index, item) {
                        $("select[name='RoleId']").append("<option value='" + item.Id + "'>" + item.RoleName + "</option>");
                    });
                    $("select[name='RoleId']").val("@Model.RoleId");
                    form.render("select");
                }
            }
        });

        form.val('', {
            'UserName': "@Model.UserName",
            'TrueName': "@Model.TrueName",
            'IDNumber': "@Model.IDNumber",
            'PhoneNumber': "@Model.PhoneNumber",
        })
        form.on("submit(save)", function(formdata) {
            formdata.field.Id = "@Model.Id";
            formdata.field.RoleName = $("select[name='RoleId'] option:selected").text();
            $.ajax({
                url: '/SysUser/Edit',
                data: formdata.field,
                success: function(res) {
                    if (res.Code == 200) {
                        layer.msg('保存成功', {
                            time: 1000
                        }, function() {
                            parent.layer.closeAll('iframe');
                        });
                    } else {
                        layer.msg(res.Message);
                    }
                }
            });
            return false;
        })
        $("#cancel").click(function() {
            parent.layer.closeAll();
            return false;
        })
    })
</script>
}
